package com.yh.servlet.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yh.service.UserService;
import com.yh.service.impl.UserServiceImpl;

//@WebServlet("/admin/user-delete.let")
public class UserDeleteServlet extends HttpServlet {
	
	private UserService userService = new UserServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			Integer userid = Integer.valueOf(req.getParameter("userId"));
			userService.delete(userid);
			req.setAttribute("msg", "删除用户成功");
			req.setAttribute("href", "admin/user-list.let");
		} catch (Exception e) {
			e.printStackTrace();//记调试日志
			req.setAttribute("error", "删除用户失败:"+e.getMessage());
		}
		req.getRequestDispatcher("/admin/msg.jsp").forward(req, resp);
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
